#include <salvo.h>

/************************************************************
****                                                     ****
**                                                         **
IntVector()

Periodic interrupt via Timer2 occurs every bit time.  TMR2
is reloaded automatically from period register PR2.  Clear 
the interrupt flag and call Salvo's timer routine.

**                                                         **
****                                                     ****
************************************************************/

#if   defined(SYSA) \
   || defined(SYSE) \
   || defined(SYSF) \
   || defined(SYSH) \
   || defined(SYSP)

#define TMR2_RELOAD 	200  	/* 500Hz ints @ 4MHz 	*/

void Init( void )
{	
	/* set TMR2 postcalar to be 1:10, with 		*/
	/*  reload value to give 500Hz for 4MHz		*/
	/*  xtal, and turn TMR2 on.	TMR2 is used to	*/
	/*  call the Salvo system timer.			*/
	PR2 = TMR2_RELOAD;
	T2CON = 0x4C; 
	
	/* enable TMR2 interrupts, enable 			*/
	/*  peripheral interrupts, enable (global) 	*/
	/*  interrupts.								*/
	#if   defined(SYSA) || defined(SYSF) || defined(SYSH) \
	  ||  defined(SYSP) 
	TMR2IE          = 1;
	PEIE            = 1; 
	#elif defined(SYSE)
	PIE1bits.TMR2IE = 1;
	INTCONbits.PEIE = 1;
	#endif
}


#if   defined(SYSA) \
   || defined(SYSF) \
   || defined(SYSH) \
   || defined(SYSP)

#if   defined(SYSA) \
   || defined(SYSH) \
   || defined(SYSF) 
void interrupt IntVector( void )
#elif defined(SYSP)
#pragma vector=0x08
__interrupt void IntVector( void )
#endif
{
	if ( TMR2IE && TMR2IF )	{
		TMR2IF = 0;
					
		OSTimer();
	}
}

#elif defined(SYSE)

#pragma interrupt ISRHigh save=PROD,section(".tmpdata")

void ISRHigh( void )
{
	if ( PIE1bits.TMR2IE && PIR1bits.TMR2IF ) {
		PIR1bits.TMR2IF = 0;
		
		OSTimer();
	}
}

#pragma code IntVectorHigh = 0x08
void IntVectorHigh( void )
{ 	
	_asm
	goto	ISRHigh
	_endasm
}

#endif

#endif
